package com.ruoyi.web.controller.system.biz;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.Assess;
import com.ruoyi.system.domain.dto.AssessDTO;
import com.ruoyi.system.domain.dto.ReportStudentDTO;
import com.ruoyi.system.domain.dto.ReportTeamDTO;
import com.ruoyi.system.service.IAssessService;
import com.ruoyi.system.service.IAssessUserService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/system/report")
public class ReportController extends BaseController {

    @Autowired
    private IAssessService assessService;
    @Autowired
    private IAssessUserService assessUserService;

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/student")
    public TableDataInfo studentList(AssessDTO assessDTO) {
        startPage();
        Assess assess = new Assess();
        BeanUtils.copyProperties(assessDTO, assess);
        assess.setOpenTarget("学生");
        LoginUser loginUser = getLoginUser();
        assess.setTaskCreator(loginUser.getUserId().toString());
        assess.setCreateDept(getDeptId() == null ? null : getDeptId().toString());
        List<Assess> list = assessService.selectAssessList(assess);
        return getDataTable(list);
    }

    @GetMapping("/user/list")
    public TableDataInfo userList(Long taskId, Integer type) {
        startPage();
        List<Map<String, Object>> list = assessUserService.selectAssessListByTaskId(taskId, type);
        return getDataTable(list);
    }


    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/teacher")
    public TableDataInfo teacherList(AssessDTO assessDTO) {
        startPage();
        Assess assess = new Assess();
        BeanUtils.copyProperties(assessDTO, assess);
        assess.setOpenTarget("教师");
        assess.setCreateDept(getDeptId() == null ? null : getDeptId().toString());
        List<Assess> list = assessService.selectAssessList(assess);
        return getDataTable(list);
    }


    /**
     * 获取学生报告详情
     */
    @GetMapping("/student/info")
    public AjaxResult studentReportInfo(ReportStudentDTO reportStudentDTO) {
        return success(assessService.reportInfo(reportStudentDTO));
    }


    /**
     * 获取团体报告
     */
    @GetMapping("/school/info")
    public AjaxResult schoolReportInfo(ReportTeamDTO reportDTO) {
        Map<String, Object> map = assessService.schoolReportInfo(reportDTO);
        return success(map);
    }


    /**
     * 获取班级年级报告详情
     */
    @GetMapping("/grade-class/info")
    public AjaxResult gradeClassReportInfo(ReportTeamDTO reportDTO) {
        Map<String, Object> map = assessService.gradeClassReportInfo(reportDTO);
        return success(map);
    }

    /**
     * 获取区域报告详情
     */
    @GetMapping("/region/info")
    public AjaxResult regionReportInfo(ReportTeamDTO reportDTO) {
        Map<String, Object> map = assessService.regionReportInfo(reportDTO);
        return success(map);
    }

}
